'use strict';

module.exports = app => {
  const {
    INTEGER,
    STRING,
    DATE,
    FLOAT,
  } = app.Sequelize;
  const Productinfo = app.model.define('productinfo', {
    id: {
      type: INTEGER,
      allowNull: false,
      primaryKey: true,
      autoIncrement: true,
      comment: '序号',
    },
    productname: {
      type: STRING(200),
      comment: '商品名字',
    },
    explain: {
      type: STRING,
      comment: '说明',
    },
    tid: {
      type: STRING,
      comment: '所属类型',
    },
    type: {
      type: STRING,
      comment: '类型',
    },
    price: {
      type: FLOAT,
      comment: '价格',
    },
    model: {
      type: 'STRING',
      comment: '型号',
    },
    tuji: {
      type: 'INTEGER',
      comment: '是否推荐',
    },
    activeprice: {
      type: FLOAT,
      comment: '活动价格',
    },
    activepricenum: {
      type: INTEGER,
      comment: '活动数量',
    },
    weight: {
      type: FLOAT,
      comment: '重量',
    },
    salesvolume: {
      type: INTEGER,
      comment: '销量',
    },
    fatiguereview: {
      type: INTEGER,
      comment: '评论',
    },
    integral: {
      type: INTEGER,
      comment: '送积分',
    },
    stock: {
      type: INTEGER,
      comment: '库存',
    },
    collection: {
      type: INTEGER,
      comment: '收藏人数',
    },
    productImg: {
      type: STRING(200),
      field: 'productImg',
      comment: '商品显示图片',
    },
    createdDate: {
      type: DATE,
      comment: '创建类型时间',
      field: 'createdDate',
    },
  }, {
    freezeTableName: true,
    timestamps: false, // 去除createAt updateAt
  });
  Productinfo.associate = function() {
    app.model.Productinfo.belongsTo(app.model.Producttype, {
      foreignKey: 'tid',
      targetKey: 'id',
    });
    app.model.Productinfo.hasOne(app.model.Productimg, {
      foreignKey: 'sid',
    });
    app.model.Productinfo.hasMany(app.model.Productevaluate, {
      foreignKey: 'sid',
      targetKey: 'id',
    });
    app.model.Productinfo.hasMany(app.model.Productparameter, {
      foreignKey: 'sid',
      targetKey: 'id',
    });
  };
  return Productinfo;
};
